package service

import (
	"context"
	"shopAdd-srv/dao"
	"shopAdd-srv/internal/model"
	__ "shopAdd-srv/proto"
	"strconv"
)

type Shop struct {
	__.UnimplementedShopServer
}

func (s *Shop) ShopAdd(_ context.Context, in *__.ShopAddReq) (*__.ShopAddResp, error) {

	shopAddService := dao.NewShopService()
	add, err := shopAddService.ShopAdd(model.Shop{
		Name:   in.Name,
		Price:  float64(in.Price),
		Number: int(in.Number),
		UserId: int(in.UserId),
	})
	if err != nil {
		return nil, err
	}

	return &__.ShopAddResp{
		ShopId: strconv.Itoa(int(add)),
	}, nil
}
